package com.itcast.dao;

import com.itcast.domain.Shopping;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ShoppingDao  {
    /**
     * 通过id查询
     * @param id
     * @return
     */
    @Select("select * from shopping where id = #{id}")
    Shopping findById(String id);

    /**
     * 创建购物车商品
     * @param shopping
     * @return
     */
    @Insert("insert into shopping(id,name,price,number,url) values(#{id},#{name},#{price},#{number},#{url})")
    int save(Shopping shopping);

    @Update("update shopping set number=#{number} where id=#{id}")
    int update(Shopping shopping);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from shopping")
    List<Shopping> findAll();

    @Delete("delete from shopping where id=#{id}")
    int deleteShop(String id);

    @Delete("delete from shopping")
    int deleteAll();
}
